/**
 * User 业务逻辑实现类
 * @author yanwl
 * @date 2015-03-20
 */
package com.company.example.service.impl;

import com.company.example.core.common.DaoHelper;
import com.company.example.core.util.AssertUtil;
import com.company.example.model.pojo.Group;
import com.company.example.model.pojo.User;
import com.company.example.service.GroupService;
import com.company.example.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;


@Service
public class UserServiceImpl  implements UserService {
	//声明工作空间
	private final static String nameSpace = "com.maven.demo.mapper.UserMapper";
	@Resource
	private GroupService groupService;
	
	@Transactional(propagation = Propagation.REQUIRES_NEW)
	@Override
	public boolean insertUser(User user) {
		boolean i = DaoHelper.insert(nameSpace, "insertUser", user);
//		return DaoHelper.insert(nameSpace, "insertUser", user);

		Group g = new Group();
		g.setName("分组2");
		g.setCreateTime(new Date());
		g.setNum(BigDecimal.valueOf(1));
		groupService.insertGroup(g);

		AssertUtil.assertTrue(false);
		return i;
	}

	@Override
	public boolean updateUser(User user) {
		return DaoHelper.update(nameSpace, "updateUser", user);
	}

	@Override
	public User selectUser(Map<String, Object> map) {
		return (User)DaoHelper.query(nameSpace, "selectUser", map);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<User> selectAllUsers() {
		return (List<User>)DaoHelper.list(nameSpace, "selectAllUsers", "");
	}

	@Override
	public boolean deleteUser(Integer userId) {
		return DaoHelper.delete(nameSpace, "deleteUser", userId);
	}
}
